package com.jl15988.mybatispluskit.join.injector.methods;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.jl15988.mybatispluskit.join.enums.JoinSqlMethod;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * Lambda 关联查询列表方法
 * 
 * @author Jalon
 * @since 2025/1/1
 */
public class SelectJoinLambdaList extends AbstractJoinMethod {
    
    /**
     * 构造函数
     */
    public SelectJoinLambdaList() {
        super(JoinSqlMethod.SELECT_JOIN_LAMBDA_LIST);
    }
    
    /**
     * 注入映射语句
     * 
     * @param mapperClass Mapper 类
     * @param modelClass 实体类
     * @param tableInfo 表信息
     * @return 映射语句
     */
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        // 构建 SQL 语句
        String sql = buildSql(tableInfo, null);
        
        // 创建 SqlSource
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        
        // 创建 MappedStatement
        return this.addSelectMappedStatementForTable(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo);
    }
}